﻿using System;
using Tensorflow.Keras.Utils;

namespace Tensorflow.Keras.Engine
{
    public partial class Layer
    {
        Tensors FunctionalConstructionCall(Tensors inputs)
        {
            if (base_layer_utils.needs_keras_history(inputs))
                base_layer_utils.create_keras_history(inputs);

            Tensors outputs = null;
            using var ctxManager = CallContext.enter(build_graph: true);

            var graph = keras.backend.get_graph();
            graph.as_default();

            var scope = ops.name_scope(_name_scope());
            scope.__enter__();

            MaybeBuild(inputs);

            // Wrapping `call` function in autograph to allow for dynamic control
            // flow and control dependencies in call. We are limiting this to
            // subclassed layers as autograph is strictly needed only for
            // subclassed layers and models.
            // tf_convert will respect the value of autograph setting in the
            // enclosing tf.function, if any.
            if (!dynamic)
                throw new NotImplementedException("");

            outputs = Call(inputs);
                
            _set_connectivity_metadata_(inputs, outputs);
            _handle_activity_regularization(inputs, outputs);
            _set_mask_metadata(inputs, outputs, null);

            scope.__exit__();
            graph.Exit();

            return outputs;
        }
    }
}
